from flask  import Flask,views,url_for,jsonify,render_template


app = Flask(__name__)
app.config.update({
    'DEBUG': True,
    'TEMPLATES_AUTO_RELOAD': True
})


class JSONView(views.View):
    def get_data(self):
        raise NotImplementedError

    def dispatch_request(self):
        return jsonify(self.get_data())


class ListView(JSONView):
    def get_data(self):
        return {"username":'video','password':'123244'}


app.add_url_rule('/list/',endpoint='my_list', view_func=ListView.as_view('list'))

with app.test_request_context():
    print(url_for('my_list'))


class ADSView(views.View):
    def __init__(self):
        super(ADSView,self).__init__()
        self.context = {
            'ads':'广告界面'
        }


class LoginView(ADSView):
    def dispatch_request(self):
        self.context.update({
            'username':'Jacky'
        })
        return render_template('login.html',**self.context)


class RegistView(ADSView):
    def dispatch_request(self):
        return render_template('regist.html',**self.context)

app.add_url_rule('/login/',view_func=LoginView.as_view('login'))
app.add_url_rule('/regist/',view_func=RegistView.as_view('regist'))


@app.route('/')
def Index():
    return "Flask标准类视图"


if __name__ == "__main__":
    app.run(debug=True)

